#define _GNU_SOURCE // 声明可以使用扩展语法
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>  // gettid()是当前库的一个扩展语法 

void * first_thread(void *arg)
{
    printf("first thread running... tid: %d\n", gettid());
    return NULL;
}

void * second_thread(void *arg)
{
    printf("second thread running... tid: %d\n", gettid());
    return NULL;
}


int main(int argc, char *argv[])
{
    printf("main thread running... tid: %d\n", gettid());

    // 创建线程
    pthread_t pid1, pid2;
    pthread_create(&pid1, NULL, first_thread, NULL);
    pthread_create(&pid2, NULL, second_thread, NULL);

    pthread_join(pid1, NULL);
    pthread_join(pid2, NULL);

    printf("main thread end... tid: %d , pid1:%ld, pid2:%ld \n", gettid(), pid1, pid2);

    return 0;
}